package com.example.zx_springboot.service.iml;

import com.example.zx_springboot.entity.ZxUser;
import com.example.zx_springboot.entity.Zxorder;
import com.example.zx_springboot.mapper.ZxOrderMapper;
import com.example.zx_springboot.service.ZxOrderService;
import com.github.pagehelper.Page;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class ZxOrderiml implements ZxOrderService {
    @Autowired
    private ZxOrderMapper zxOrderMapper;
    @Override
    public PageInfo findByPage(Integer pageNum, Integer pageSize, String order_id) {

            // 设置分页 页数和 页面最大数量，会自动达到分页的效果
            Page<ZxUser> page = PageHelper.startPage(pageNum, pageSize);
            //查询出来所有内容，会根据上面设置的分页参数显示
            if(order_id!="") {
                order_id = "%" + order_id + "%";
                List<Zxorder> zxorders = zxOrderMapper.SelectName(order_id);
                PageInfo<Zxorder> orderPageInfo = new PageInfo<>(zxorders);
                System.out.println("当前页"+orderPageInfo.getPageNum());
                System.out.println("总页数"+orderPageInfo.getPages());
                System.out.println("页大小"+orderPageInfo.getSize());
                System.out.println("总记录数"+orderPageInfo.getTotal());
                System.out.println("当前页数据"+orderPageInfo.getList());

                return orderPageInfo;
            }else {
                List<Zxorder> zxorders = zxOrderMapper.getall();
                PageInfo<Zxorder> orderPageInfo = new PageInfo<>(zxorders);
                System.out.println("当前页"+orderPageInfo.getPageNum());
                System.out.println("总页数"+orderPageInfo.getPages());
                System.out.println("页大小"+orderPageInfo.getSize());
                System.out.println("总记录数"+orderPageInfo.getTotal());
                System.out.println("当前页数据"+orderPageInfo.getList());

                return orderPageInfo;
            }
    }
}
